String Operations

IDL supports many string operations, as described below:

Operation

Description

Concatenation

The Addition operator, “+”, can be used to concatenate strings together.

Formatting Data

The STRING function is used to format data into a string. The READS procedure can be used to read values from a string into IDL variables.

Case Folding

The ToLower() method returns a copy of the string converted to lowercase. Similarly, the ToUpper() method returns a copy converted to uppercase. The CapWords() method returns a copy where the first letter of each word is capitalized. See also the STRLOWCASE and STRUPCASE functions.

White Space Removal

The Compress() and Trim() methods can be used to eliminate unwanted white space. See also the STRCOMPRESS and STRTRIM functions.

Length

The Strlen() method (or STRLEN function) returns the length of the string.

Substrings

See the CharAt(), Extract(), IndexOf(), Insert(), LastIndexOf(), Remove(), Replace(), Reverse(), and Substring() methods. See also the STRPOS, STRPUT, and STRMID routines.

Splitting and Joining

The Split() method is used to break strings apart, and the Join() method can be used to join them. See also the STRSPLIT and STRJOIN functions.

Comparing Strings

The "EQ" operator can be used to directly compare two strings. The Contains(), EndsWith(), Matches(), and StartsWith() methods can be used to compare portions of strings. See also the STRCMP, STRMATCH, and STREGEX functions.